package com.wanmait.recycle.listener;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.springframework.web.context.support.WebApplicationContextUtils;

import com.github.pagehelper.PageInfo;
import com.wanmait.recycle.pojo.Article;
import com.wanmait.recycle.pojo.Firsttype;
import com.wanmait.recycle.pojo.Province;
import com.wanmait.recycle.pojo.Question;
import com.wanmait.recycle.service.ArticleService;
import com.wanmait.recycle.service.CityService;
import com.wanmait.recycle.service.ConfigService;
import com.wanmait.recycle.service.FirsttypeService;
import com.wanmait.recycle.service.ProvinceService;
import com.wanmait.recycle.service.QuestionService;
import com.wanmait.recycle.service.UserinfoService;
import com.wanmait.recycle.service.impl.ProvinceServiceImpl;

/**
 * Application Lifecycle Listener implementation class ConfigListener
 *
 */
@WebListener
public class ConfigListener implements ServletContextListener {

	
	
    /**
     * Default constructor. 
     */
    public ConfigListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce)  { 
         // TODO Auto-generated method stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce)  { 
    	ServletContext application = sce.getServletContext();
    	ConfigService configService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(ConfigService.class);
    	Map<String, Map<String,String>> config = configService.findAllConfig();
    	ProvinceService provinceService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(ProvinceService.class);
    	List<Province> provinces = provinceService.findAll();
    	FirsttypeService firsttypeService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(FirsttypeService.class);
    	List<Firsttype> firsttypes = firsttypeService.findAll();
    	ArticleService articleService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(ArticleService.class);
    	PageInfo<Article> articles = articleService.findEnableArticle();
    	QuestionService questionService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(QuestionService.class);
    	PageInfo<Question> questiones = questionService.findAllByPage();
    	
    }
	
}
